<template>
  <view class="content">
    <image class="logo" src="@/static/logo.png" />
    <view class="text-area">
      <text class="title">{{ title }}</text>
    </view>
  </view>
</template>

<script setup lang="ts">
import Axios from 'axios'
import {fetchPromise}  from '../../utils/fetch'
const params = {
  _api_key:"922f5cea636ff981d00fa83b29af25b2",
  buildType:"ios",
  class:'fetch'
}
// fetchPromise(`https://www.pgyer.com/apiv2/app/getCOSToken`, params, 'post').then((res) => {
//     console.log('getCOSToken', res)
//     // response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
//   }).catch((rejected) => {
//     console.log('catch rejected', rejected)
//     throw new Error(res); // 抛出一个新的错误对象
//   });


const fetchFun = () => {
fetch('https://www.pgyer.com/apiv2/app/getCOSToken', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
  },
  body: JSON.stringify(params)
}).then(response => {
    if (!response.ok) {
      throw new Error('Network response was not ok');
    }
    return response.json();
  }).then(data => {
    console.log(data);
  }).catch(error => {
    console.error('Fetch failed:', error);
  });
}
fetchFun()
import { ref } from 'vue'
const title = ref('xdy')

const getCOSToken = () =>{
  Axios({
    method: 'post',
    url: 'https://www.pgyer.com/apiv2/app/getCOSToken',
    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
    data:{
      _api_key:"922f5cea636ff981d00fa83b29af25b2",
      buildType:"ios"
    }
  })
  .then((res) => {
    const resData = res.data.data
    console.log('getCOSToken', resData)
    // response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
  });
}
// getCOSToken()

</script>

<style>
.content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.logo {
  height: 200rpx;
  width: 200rpx;
  margin-top: 200rpx;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 50rpx;
}

.text-area {
  display: flex;
  justify-content: center;
}

.title {
  font-size: 36rpx;
  color: #8f8f94;
}
</style>
